package com.station.administrators.controller;

import com.open.capacity.common.util.JsonResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.common.model.ActivityModel;
import com.station.administrators.service.BusinessActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 商家活动管理
 * @Description: TODO
 * @date 2021/6/25/9:48
 */
@Api(tags = "商家活动管理")
@RestController
@RequestMapping("/businessActivity")
public class BusinessActivityController {
    @Autowired
    private BusinessActivityService businessActivityService;
    @ApiOperation("审核商家活动")
    @PreAuthorize("")
    @PostMapping("/update")
    public Object update(ActivityModel activity){
        businessActivityService.update(activity);
        return JsonResult.ok();
    }
    @ApiOperation("删除商家活动")
    @PostMapping("/delete")
    public Object delete(Long id){
        businessActivityService.delete(id);
        return JsonResult.ok();
    }
    @ApiOperation("根据id查询商家活动")
    @GetMapping("/findById")
    public Object findById(Long id){
        ActivityModel activity=businessActivityService.findById(id);
        return Result.succeed(activity,"a");
    }
    @ApiOperation("查询所有商家活动")
    @GetMapping("/findAll")
    public Object findAll(ActivityModel activity){
        List<ActivityModel> activityList =businessActivityService.findAll(activity);
        Integer count=businessActivityService.getCount(activity);
        Map<String,Object> map=new HashMap<>();
        map.put("activity",activityList);
        map.put("count",count);
        return Result.succeed(map,"");
    }


}
